"use strict";

import Vue from "vue";
import axios from "axios";
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import "./element"

// Full config:  https://github.com/axios/axios#request-config
// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';


axios.interceptors.request.use(
    config => {
        NProgress.start()
        let token = localStorage.getItem('token')
        if (token) {
            let token = localStorage.getItem('token')
            config.headers.Authorization = 'Bearer ' + token
        }
        return config;
    },
    error => {
        // Do something with request error
        return Promise.reject(error);
    }
);

// Add a response interceptor
axios.interceptors.response.use(
    response => {
        NProgress.done()
            // Do something with response data
        return response;
    },
    error => {
        Vue.prototype.$message.error(error.response.data)
            // Do something with response error
        return Promise.reject(error);
    }
);